#include <iostream>
#include <inicpp.hpp>
#include "Server.h"
#include "Utils.hpp"
#include "Config.h"


int main() {
    try {
        Config::GetInstance().InitConfig("../config/config.ini");
        boost::asio::io_context ioc;
        boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
        signals.async_wait([&ioc](const boost::system::error_code& ec, int) {
            if (ec)
                return;
            ioc.stop();
        });
        std::make_shared<Server>(ioc, Config::GetInstance()._server_port)->StartAccept();
        ioc.run();
    }
    catch (std::exception const& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    return 0;
}
